﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BanVeXemPhim_Presentation
{
    public partial class UserControlAdminThongKeDoanhThu : UserControl
    {
        public UserControlAdminThongKeDoanhThu()
        {
            InitializeComponent();
        }
        private PhimDTO[] _dsPhim;
        private ThongKeDTO[] _dsThongKe;

        internal ThongKeDTO[] DsThongKe
        {
            get { return _dsThongKe; }
            set { _dsThongKe = value; }
        }
        public PhimDTO[] DsPhim
        {
            get { return _dsPhim; }
            set
            {
                _dsPhim = value;
                if (_dsPhim != null)
                {
                    if (_dsPhim.Length > 0)
                    {
                        this.comboBoxTenPhim.Items.Clear();
                        int n = this._dsPhim.Length;
                        for (int i = 0; i < n; i++)
                        {
                            if (_dsPhim[i] != null)
                            {
                                this.comboBoxTenPhim.Items.Add(_dsPhim[i].TenPhim);
                            }

                        }
                    }
                }
            }
        }
        private void UserControlAdminThongKeDoanhThu_Load(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            for (int i=now.Year;i>2000;i--)
            {
                comboBoxNam.Items.Add(i);
            }
            PhimControl phimControl = new PhimControl();
            DsPhim = phimControl.LayDanhSachPhim();
        }

        private void comboBoxThongKeTheo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxThongKeTheo.SelectedIndex == 0)
            {
                comboBoxTenPhim.Enabled = true;
            }
            else
            {
                comboBoxTenPhim.Enabled = false;
            }
        }

        private void comboBoxThongKeTheo_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void comboBoxTenPhim_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void comboBoxThang_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void comboBoxNam_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

        private void buttonThongKe_Click(object sender, EventArgs e)
        {
            ThongKeControl thongkeControl = new ThongKeControl();
            ThongKeDTO thongkeDto = new ThongKeDTO();
            LayThongTinThongKe(ref thongkeDto);
            DsThongKe = thongkeControl.ThongKeTheoTenPhim(thongkeDto);
            dataGridViewThongKe.DataSource = DsThongKe;
        }
        private void LayThongTinThongKe(ref ThongKeDTO thongkeDto)
        {
            thongkeDto.TenPhim = comboBoxTenPhim.Text;
            thongkeDto.Thang = comboBoxThang.SelectedIndex + 1;
            thongkeDto.Nam = DateTime.Now.Year - comboBoxNam.SelectedIndex;
        }

        
    }
}
